package com.sun.module_category.ui

import com.sun.module_base.app.BaseViewModel
import com.sun.module_base.app.ResultState
import com.sun.module_category.model.ParentBean
import com.sun.module_category.net.HttpRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

/**
 *@author:sunc
 *@time :2025/8/15 9:06
 *@desc: 描述
 */
@HiltViewModel
class CategoryViewModel @Inject constructor(private val httpRepository: HttpRepository) :
    BaseViewModel() {

    private var _categoryFlow =
        MutableStateFlow<CategoryState>(ResultState.Loading())
    val categoryFlow = _categoryFlow.asStateFlow()

    init {
        getProjectCategory()
    }


    fun getProjectCategory() {
        launchUI({ httpRepository.getProjectCategory() }, _categoryFlow)
    }
}

typealias CategoryState = ResultState<MutableList<ParentBean>?>